package cn.xxstudy.visitshop.base.fragment

import android.content.res.Configuration
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import cn.xxstudy.visitshop.R

/**
 * @author ：DELL on 2021/3/24 .
 * @packages ：cn.xxstudy.visitshop.base.fragment .
 * TODO:懒加载Fragment
 */
abstract class LazyFragment : Fragment() {
    abstract val layoutId: Int
    abstract fun loadData()

    abstract fun initView()
    fun tryResumeBundle(savedInstanceState: Bundle?) {

    }

    private var isFirstLoad = true
    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        tryResumeBundle(savedInstanceState)
        return inflater.inflate(layoutId, container, false)
    }

    override fun onResume() {
        super.onResume()
        if (isFirstLoad) {
            initView()
            loadData()
            isFirstLoad = false;
        }
    }
}